package cn.tedu.blog.server.controller.system;



import cn.tedu.blog.server.pojo.vo.CommentListVo;
import cn.tedu.blog.server.service.ICommentService;
import cn.tedu.blog.server.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "评论管理")
@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    public CommentController() {
        log.info(" 创建控制器的对象   controller ");
    }



    @ApiOperation("删除评论")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult CommentDelete(@PathVariable Long id) {
        log.info("根据ID处理删除评论业务 id: {}", id);
        commentService.deleteById(id);
        return JsonResult.ok("删除成功");
    }


    @ApiOperation("删除多条评论")
    @ApiOperationSupport(order = 300)
    @PostMapping("/deletes")
    public JsonResult deletes(Long[] id) {
        log.info("根据ID处理删除评论业务 id: {}", id);
            commentService.deleteImpl(id);
        return JsonResult.ok("删除成功");
    }


    @ApiOperation("获取评论列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult getList() {
        log.info("查询评论列表");
        List<CommentListVo> comments = commentService.getList();
        log.info("查询评论列表成功 comments:  {}", comments);
        return JsonResult.ok(comments);
    }

}
